package com.cgbl.cg.vm.mine

import android.app.Application
import android.os.Bundle
import android.text.TextUtils
import androidx.databinding.ObservableBoolean
import com.alibaba.fastjson.JSON
import com.cgbl.cg.utils.city.BeanTransferHelper
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.configs.AppConstants
import com.robot.base.util.ToastUtils
import com.robot.base.util.arouter.ARouterUtil
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand

class ResourceFileViewModel(application: Application) : GLBaseViewModel(application) {
    var pay = ObservableBoolean(false)
    var productId = ""
    var payType = ""

    val buyCommand = BindingCommand<Any>(BindingAction {
        if (TextUtils.isEmpty(productId)) {
            ToastUtils.showShort("商品为空!")
            return@BindingAction
        }
        ARouterUtil.goToActivityWithBundle(
            AppConstants.Router.Mine.A_MINE_CONFIRM_ORDER,
            Bundle().apply {
                putString(
                    AppConstants.BundleKey.SHOP_CART_BEAN, JSON.toJSONString(
                        BeanTransferHelper.createConfirmOrderProductByCourse(productId, payType)
                    )
                )
            })
    })
}